<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
 <script src="js/cookie_util.js"></script>
     <script type="text/javascript">
    	var user_id=getCookie("userId");
		console.log(user_id);
    	if(user_id!=null){//用户ID存在    		
    		$(function (){
    			$.ajax({
					url:"http://localhost:8080/carinfo/showAll.do",
					type:"post",
					data:{},
					dataType:"json",
					success:function(rs){
						if(rs.status==0){
							var cis=rs.data;
							creatCarTr(cis)
						}else{
							alert("车辆信息加载失败");
						}
					},
					error:function(){
						alert("发生异常，请稍后再试");
					}
				})		
				
			})	
    	
    	
    	
			function show(user_id){
    			$.ajax({
    				url:"http://localhost:8080/carinfo/show.do",
    				type:"post",
    				data:{"user_id":user_id},
    				dataType:"json",
    				success:function(rs){
    					if(rs.status==0){
    						$("#carinfos").html("");
    						var cis=rs.data;
    						creatCarTr(cis)
    						
    					}else{
    						alert("车辆信息加载失败");
    					}
    				},
    				error:function(){
    					alert("发生异常，请稍后再试");
    				}
    			})		
    		}
   	
    	
    		function search(){
    			var keywords=$("#keywords").val();
    			var type=$("#type").val();
    			$.ajax({
    				url:"http://localhost:8080/carinfo/search.do",
    				type:"post",
    				data:{"type":type,"keywords":keywords},
    				dataType:"json",
    				success:function(rs){
    					if(rs.status==0){
    						$("#carinfos").html("");
							var cis=rs.data;
							creatCarTr(cis);
    					}else{
    						alert(rs.msg);
    					}
    				},
    				error:function(){
    					alert("发生异常，请稍后再试");
    				}
    			})		
    		}
    	
    		
    		function creatCarTr(cis){
    			for(var i=0;i<cis.length;i++){
					var id=cis[i].id;
					var plate=cis[i].plate;
					var brand=cis[i].brand;
					var model=cis[i].model;
					var color=cis[i].color;
					var price=cis[i].price;
					var date=cis[i].date;
					var user_name=cis[i].user_name;
					var user_id=cis[i].user_id;
					var trs='<tr>';
						trs+='<td style="text-align:left; padding-left:20px;">'+plate+'</td>';
						trs+='<td width="10%">'+brand+'</td>';
						trs+='<td>'+model+'</td>';
						trs+='<td>'+color+'</td>';
						trs+='<td>'+price+'</td>';
						trs+='<td>'+date+'</td>';
						trs+='<td><div class="button-group"><button class="button border-blue" href="javascript:void(0)" onclick="show('+user_id+')"> '+user_name+'</button> </div></td>';
						trs+='</tr>';
					var $trs=$(trs);
					$("#carinfos").append($trs);
				}
    		}
				
		}else{//用户ID不存在
			top.location.href="http://localhost:8080/login.html"
		}
    </script>  
</head>
<body>

  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 车辆信息</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
	 <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <if condition="$iscid eq 1">
          <li>
            <select id="type" name="cid" class="input" style="width:110px; line-height:17px;">
              <option value="">-请选择分类-</option>
              <option value="1">车牌</option>
              <option value="2">品牌</option>
              <option value="3">用户</option>
            </select>
          </li>
        </if>
        <li>
          <input type="text" placeholder="请输入搜索关键字" id="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <button class="button border-main icon-search" onclick="search()">搜索</button></li>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">车牌</th>
        <th>品牌</th>
        <th>型号</th>
        <th>颜色</th>
        <th>价格</th>
        <th width="10%">购买日期</th>
        <th width="310">所属用户</th>
      </tr>
      <tbody id="carinfos">
        
       </tbody>

    </table>
  </div>

</body>
</html>